package test04;


import java.util.Random;

public class MyThread4 extends Thread {
    static final double MIN = 0.01;
    static double money = 100;
    static int count = 3;

    @Override
    public void run() {
        synchronized (MyThread4.class) {
            if (count == 0) {
                System.out.println(getName() + "没抢到红包");
            } else {
                double prize = 0;
                if (count == 1) {
                    prize = money;

                } else {
                    double bound = money - (MIN * count);
                    Random r = new Random();
                    prize = r.nextDouble(bound);
                    if (prize < MIN) prize = MIN;
                }
                money = money - prize;
                count--;
                System.out.println(getName() + "抢到了" + prize + "元");
            }
        }
    }
}
